package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShopCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api("C端购物车接口")
public class ShopCartController {
    @Autowired
    private ShopCartService shopCartService;
    /**
     * 购物车的添加
     */
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result addCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车内容为: {}",shoppingCartDTO);
        shopCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    /**
     * 购物车的回显
     */
    @ApiOperation("显示购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> shoppingCarts = shopCartService.showShoppingCart();
        return Result.success(shoppingCarts);
    }
    @PostMapping("/sub")
    @ApiOperation("修改购物车数量")
    public Result subShoppingCart(Long id){
//        shopCartService.deleteShoppingCart(id);
        return Result.success();
    }
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result cleanShoppingCart(){
        shopCartService.cleanShoppingCart();
        return Result.success();
    }
}
